home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / hostmaint / host2txt.awk next >
Encoding:
AWK Script  |  1996-10-25  |  1.3 KB  |  64 lines

  1. BEGIN { origin = "msu.edu"; nredef = 0
  2.   }
  3. /^[0-9]/ {
  4.   global = 0
  5.   nn = 0
  6.   c = index($0,"#")
  7.   if (c == 0) {
  8.     nl = split($0,nlist)
  9.     comment = ""
  10.   } else {
  11.     nl = split(substr($0,1,c-1),nlist)
  12.     comment = substr($0,c+1,length($0))
  13.   }
  14.   ip = nlist[1]
  15.   printf "HOST: %s: ", ip
  16.   for (n=2; n <= nl; n++) {
  17.     name = nlist[n]
  18.     if (name != "") {
  19.       np = split(name,part,".")
  20.       found = 0
  21.       for (i=0; i < nn; i++) {
  22.     if (part[1] == pname[i]) {
  23.       if (np == 3) global = 1
  24.       found = 1
  25.       break
  26.     }
  27.       }
  28.       if (!found) {
  29.     if (nn) printf ", "
  30.     printf "%s", name
  31.     pname[nn++] = part[1]
  32.       }
  33.     }
  34.   }
  35.   sub("^  *","",comment)
  36.   sub("  *$","",comment)
  37.   cpu = ""
  38.   opsys = ""
  39.   if (comment ~ /:.*:/) {
  40.     i = index(comment,":")
  41.     opsys = substr(comment,1,i-1)
  42.     comment = substr(comment,i+1,length(comment))
  43.     i = index(comment,":")
  44.     cpu = substr(comment,1,i-1)
  45.     comment = substr(comment,i+1,length(comment))
  46.     sub("^ *"," ",cpu)
  47.     sub("^  *","",comment)
  48.   }
  49.   printf ":%s:%s:: ", cpu, opsys
  50.   if (global) printf "global"
  51.   if (comment != "") {
  52.     if (global) printf ","
  53.     printf "comment=%s", comment
  54.   }
  55.   printf "\n"
  56.   next
  57. }
  58. /^#MX:/ { print substr($0,2,length($0)); next }
  59. /^#/ { print ";" substr($0,2,length($0)) }
  60. /^HOST:/ { print }
  61. /^MX:/ { print }
  62. /^;/ { print }
  63. { next }
  64.